﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace DARE
{
    public class CViewPort
    {

    #region fields

        private Rectangle m_displayRectangle;
        private RenderTarget2D m_renderTarget = null;

    #endregion

    #region properties

        /// <summary>
        /// 
        /// </summary>
        public Rectangle DisplayRectangle
        {
            get { return m_displayRectangle; }
            set { m_displayRectangle = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public RenderTarget2D RenderTarget
        {
            get { return m_renderTarget; }
            set 
            {
                if (m_renderTarget != null)
                    m_renderTarget = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public Rectangle RenderArea
        {
            get { return m_displayRectangle; }
            set
            {
                m_displayRectangle = value;
                m_renderTarget = new RenderTarget2D(
                    DARE.CDare.Instance.GraphicsDevice,
                    value.Width,
                    value.Height,
                    false,
                    SurfaceFormat.Color,
                    DepthFormat.Depth24Stencil8,
                    4,
                    RenderTargetUsage.PlatformContents);
            }
        }

    #endregion

    #region ctor

        public CViewPort()
        {
            RenderArea = new Rectangle(0, 0, 
                CDare.Instance.Config.Video.ResolutionWidth, 
                CDare.Instance.Config.Video.ResolutionHeight);
        }

    #endregion

    #region update/draw

        public void Draw()
        {
            DARE.CDare.Instance.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);
            DARE.CDare.Instance.SpriteBatch.Draw(m_renderTarget, m_displayRectangle, Color.White);
            DARE.CDare.Instance.SpriteBatch.End();
        }

    #endregion

    }
}
